from django.db import models


# Create your models here.
class UserModel(models.Model):
    uid = models.AutoField(auto_created=True, primary_key=True)

    name = models.CharField(max_length=30, unique=True, db_index=True)

    age = models.IntegerField(default=18)

    sex = models.BooleanField(default=True)

    # null=True 表示可以为空 blank=True 在Admin管理页面可以为空
    info = models.TextField(null=True, blank=True)

    salary = models.FloatField(default=100000.00)

    # 日期
    birthday = models.DateField(default='2025-05-01')
    birthday1 = models.DateTimeField(auto_now=True)
    birthday2 = models.DateTimeField(auto_now_add=True)

    # 文件和图片
    icon = models.FileField(null=True, upload_to='static/uploads')
    icon2 = models.ImageField(null=True, upload_to='static/uploads')

    # 其他约束
    choices = ((1, '青铜'), (2, '大师'), (3, '王者'))
    user_type = models.IntegerField(choices=choices, default=1,
                                    name='utype', verbose_name='用户类型')
    user_type2 = models.IntegerField(editable=False, default=1,
                                     db_column='utype2', verbose_name='用户类型')


class CRUDModel(models.Model):
    name = models.CharField(max_length=30, unique=True)
    age = models.IntegerField(default=18)

    class Meta:
        # 表名
        db_table = 'tb_crud'

    def __repr__(self):
        return f'{self.name} - {self.age}'

    def __str__(self):
        return f'{self.name} - {self.age}'

